//
//  GJFMerchantDetailCaseTableViewCell.m
//  Wedding
//
//  Created by 郭静芬 on 2017/1/4.
//  Copyright © 2017年 郭静芬. All rights reserved.
//

#import "GJFMerchantDetailCaseTableViewCell.h"
#import "GJFCaseCollectionViewCell.h"
#import "GJFInspirationViewController.h"

@interface GJFMerchantDetailCaseTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong)UICollectionView *collectionV;
@property (nonatomic, strong)UILabel *title;
@end

@implementation GJFMerchantDetailCaseTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self collectionV];
        self.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    return self;
}

- (void)setCaseModel:(GJFCaseModel *)caseModel {
    _caseModel = caseModel;
    self.title.text = caseModel.title;
    [self.collectionV reloadData];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.title.frame = CGRectMake(10 * XX, 110, WIDTH - 30 * XX, 25 * YY);
}
#pragma mark - CollectionView中分区数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
#pragma mark - CollectionView每个分区中item数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.caseModel.imgs.count;
}
#pragma mark - CollectionView中item的内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    GJFCaseCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ImgsCell" forIndexPath:indexPath];
    cell.imgsModel = self.caseModel.imgs[indexPath.row];
    return cell;
}
#pragma mark - CollectionView跳转
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (_caseDelegate && [_caseDelegate respondsToSelector:@selector(caseSkipDetailWithArray:IndexPath:)]) {
        [self.caseDelegate caseSkipDetailWithArray:self.caseModel.imgs IndexPath:indexPath];
    }
}

- (UICollectionView *)collectionV {
    if (!_collectionV) {
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(90 * YY, 90 * YY);
        layout.sectionInset = UIEdgeInsetsMake(20 * XX, 10 * YY, 5 * XX, 15 * YY);
        layout.minimumLineSpacing = 5;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        _collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 100 * YY) collectionViewLayout:layout];
        _collectionV.backgroundColor = [UIColor whiteColor];
        _collectionV.delegate = self;
        _collectionV.dataSource = self;
        _collectionV.showsHorizontalScrollIndicator = NO;
        [self.contentView addSubview:_collectionV];
        
        [_collectionV registerClass:[GJFCaseCollectionViewCell class] forCellWithReuseIdentifier:@"ImgsCell"];
    }
    return _collectionV;
}
- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = [UIColor darkGrayColor];
        [self.contentView addSubview:_title];
    }
    return _title;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
